<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var goodDaysToRobBank = function (security, time) {
      const n = security.length;
      const left = new Array(n).fill(0);
      const right = new Array(n).fill(0);
      for (let i = 1; i < n; i++) {
        if (security[i] <= security[i - 1]) {
          left[i] = left[i - 1] + 1;
        }
        if (security[n - i - 1] <= security[n - i]) {
          right[n - i - 1] = right[n - i] + 1;
        }
      }

      const ans = [];
      for (let i = time; i < n - time; i++) {
        if (left[i] >= time && right[i] >= time) {
          ans.push(i);
        }
      }
      return ans;
    };
    console.log(goodDaysToRobBank(security = [5, 3, 3, 3, 5, 6, 2], time = 2))
  </script>
</body>

</html>